﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="AlimonyClaim", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(AlimonyClaim))]
    public class AlimonyClaimSerializer : global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.ClaimSerializer {
        
        public AlimonyClaimSerializer(IAlimonyClaim clazz) : 
                base(clazz) {
        }
        
        protected new IAlimonyClaim clazz {
            get {
                return ((IAlimonyClaim)(base.clazz));
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("PetitionerConfirmation");
            if (clazz.PetitionerConfirmation!=null) {
                global::Xtee.Core.SerializationMetadata metaPetitionerConfirmation = this.GetMetaData(clazz.PetitionerConfirmation);
                Writer.WriteTypeAttribute(metaPetitionerConfirmation.TypeQualifiedName.Namespace, metaPetitionerConfirmation.TypeQualifiedName.Name);
                metaPetitionerConfirmation.NewSerializer(clazz.PetitionerConfirmation).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PetitionerConfirmation");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("HasLegalBarriers");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.HasLegalBarriers))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("IsParentInAlimony");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.IsParentInAlimony))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("IsParent");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.IsParent))).ToString());
            Writer.WriteEndElement();
            if (((clazz.DebtSettlement == null) 
                        || (clazz.DebtSettlement.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "DebtSettlement");
            }
            for (int x = 0; ((clazz.DebtSettlement != null) 
                        && (x < clazz.DebtSettlement.Count)); x = (x + 1)) {
                Writer.WriteStartElement("DebtSettlement");
                if (clazz.DebtSettlement[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaDebtSettlement = this.GetMetaData(clazz.DebtSettlement[x]);
                    Writer.WriteTypeAttribute(metaDebtSettlement.TypeQualifiedName.Namespace, metaDebtSettlement.TypeQualifiedName.Name);
                    metaDebtSettlement.NewSerializer(clazz.DebtSettlement[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DebtSettlement");
                }
                Writer.WriteEndElement();
            }
            if (((clazz.RepresentativeData == null) 
                        || (clazz.RepresentativeData.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "RepresentativeData");
            }
            for (int x = 0; ((clazz.RepresentativeData != null) 
                        && (x < clazz.RepresentativeData.Count)); x = (x + 1)) {
                Writer.WriteStartElement("RepresentativeData");
                if (clazz.RepresentativeData[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaRepresentativeData = this.GetMetaData(clazz.RepresentativeData[x]);
                    Writer.WriteTypeAttribute(metaRepresentativeData.TypeQualifiedName.Namespace, metaRepresentativeData.TypeQualifiedName.Name);
                    metaRepresentativeData.NewSerializer(clazz.RepresentativeData[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RepresentativeData");
                }
                Writer.WriteEndElement();
            }
            if (clazz.RepresentativeOrganisationData!=null) {
                Writer.WriteStartElement("RepresentativeOrganisationData");
                global::Xtee.Core.SerializationMetadata metaRepresentativeOrganisationData = this.GetMetaData(clazz.RepresentativeOrganisationData);
                Writer.WriteTypeAttribute(metaRepresentativeOrganisationData.TypeQualifiedName.Namespace, metaRepresentativeOrganisationData.TypeQualifiedName.Name);
                metaRepresentativeOrganisationData.NewSerializer(clazz.RepresentativeOrganisationData).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("PetitionerCase");
            if (clazz.PetitionerCase!=null) {
                global::Xtee.Core.SerializationMetadata metaPetitionerCase = this.GetMetaData(clazz.PetitionerCase);
                Writer.WriteTypeAttribute(metaPetitionerCase.TypeQualifiedName.Namespace, metaPetitionerCase.TypeQualifiedName.Name);
                metaPetitionerCase.NewSerializer(clazz.PetitionerCase).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PetitionerCase");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="PetitionerConfirmation") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>PetitionerConfirmation");
                }
                global::Xtee.Core.SerializationMetadata metaPetitionerConfirmation = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPetitionerConfirmation>(Reader, "PetitionerConfirmation", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.PetitionerConfirmation = metaPetitionerConfirmation.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPetitionerConfirmation>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("PetitionerConfirmation");
                    metaPetitionerConfirmation.NewSerializer(clazz.PetitionerConfirmation).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>PetitionerConfirmation", Reader.LocalName);
            }
            if (Reader.LocalName=="HasLegalBarriers") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>HasLegalBarriers");
                }
                clazz.HasLegalBarriers = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("HasLegalBarriers")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>HasLegalBarriers", Reader.LocalName);
            }
            if (Reader.LocalName=="IsParentInAlimony") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>IsParentInAlimony");
                }
                clazz.IsParentInAlimony = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("IsParentInAlimony")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>IsParentInAlimony", Reader.LocalName);
            }
            if (Reader.LocalName=="IsParent") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>IsParent");
                }
                clazz.IsParent = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("IsParent")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>IsParent", Reader.LocalName);
            }
            clazz.DebtSettlement = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IDebtSettlement>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "DebtSettlement")); ) {
                if (Reader.LocalName=="DebtSettlement") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>DebtSettlement");
                    }
                    global::Xtee.Core.SerializationMetadata metaDebtSettlement = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IDebtSettlement>(Reader, "DebtSettlement", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IDebtSettlement item = metaDebtSettlement.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IDebtSettlement>();
                    clazz.DebtSettlement.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("DebtSettlement");
                        metaDebtSettlement.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>DebtSettlement", Reader.LocalName);
                }
            }
            if ((clazz.DebtSettlement.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "DebtSettlement");
            }
            clazz.RepresentativeData = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IRepresentativeData>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "RepresentativeData")); ) {
                if (Reader.LocalName=="RepresentativeData") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>RepresentativeData");
                    }
                    global::Xtee.Core.SerializationMetadata metaRepresentativeData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IRepresentativeData>(Reader, "RepresentativeData", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IRepresentativeData item = metaRepresentativeData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IRepresentativeData>();
                    clazz.RepresentativeData.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("RepresentativeData");
                        metaRepresentativeData.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>RepresentativeData", Reader.LocalName);
                }
            }
            if ((clazz.RepresentativeData.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "RepresentativeData");
            }
            if (Reader.LocalName=="RepresentativeOrganisationData") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>RepresentativeOrganisationData");
                }
                global::Xtee.Core.SerializationMetadata metaRepresentativeOrganisationData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IRepresentativeOrganisationData>(Reader, "RepresentativeOrganisationData", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.RepresentativeOrganisationData = metaRepresentativeOrganisationData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IRepresentativeOrganisationData>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("RepresentativeOrganisationData");
                    metaRepresentativeOrganisationData.NewSerializer(clazz.RepresentativeOrganisationData).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="PetitionerCase") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaim>PetitionerCase");
                }
                global::Xtee.Core.SerializationMetadata metaPetitionerCase = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPetitionerCase>(Reader, "PetitionerCase", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.PetitionerCase = metaPetitionerCase.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPetitionerCase>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("PetitionerCase");
                    metaPetitionerCase.NewSerializer(clazz.PetitionerCase).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaim>PetitionerCase", Reader.LocalName);
            }
        }
    }
}
